﻿using System;
using RpcHelper;
using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.LocalEvent;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
        internal class VerRouteCollect : BasicCollect<ServiceVerRouteDAL>, IVerRouteCollect
        {
                public Guid Add (ServiceVerRoute add)
                {
                        Guid id = base.BasicDAL.Add (add);
                        this._Refresh (add.VerId, "Add");
                        return id;
                }

                private void _Refresh (long verId, string name)
                {
                        new RefreshVerRoute (name)
                        {
                                VerId = verId
                        }.AsyncPublic ();
                }

                public ServiceVerRoute[] GetRoutes (long verId)
                {
                        return base.BasicDAL.GetRoutes (verId);
                }
                public ServiceVerRoute Get (Guid id)
                {
                        ServiceVerRoute route = base.BasicDAL.Get (id);
                        if (route == null)
                        {
                                throw new ErrorException ("rpc.ver.route.not.find");
                        }
                        return route;
                }
                public void Set (ServiceVerRoute route, VerRouteSet set)
                {
                        if (set.IsEquals (route))
                        {
                                return;
                        }
                        base.BasicDAL.Set (route.Id, set);
                        this._Refresh (route.VerId, "Set");
                }
                public void Delete (ServiceVerRoute route)
                {
                        base.BasicDAL.Delete (route.Id);
                        this._Refresh (route.VerId, "Delete");
                }
                public void SetIsEnable (ServiceVerRoute route, bool isEnable)
                {
                        if (route.IsEnable != isEnable)
                        {
                                base.BasicDAL.SetIsEnable (route.Id, isEnable);
                                this._Refresh (route.VerId, "EnableStatus");
                        }
                }
        }
}
